package stream;

import org.junit.Test;

import java.beans.Customizer;
import java.io.*;
import java.net.Proxy;
import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.IntStream;

/**
 * -@Version 1.0
 * -@Author:Vpen
 * -@Date:2021/1/30 17:55
 * -@Content:
 */
public class StreamTest {
    @Test
    public void test3(){
        Socket socket = new Socket( );

    }

    @Test
    public void test2() throws IOException {
        byte[] bytes = Files.readAllBytes(Paths.get("h.txt"));
//        Files.createDirectory(Paths.get("aa"));
//        Files.delete(Paths.get("aa"));
//        Files.createFile(Paths.get("a.txt"));
        Files.delete(Paths.get("a.txt"));

    }
    @Test
    public void test1(){
        IntStream stream = IntStream.of(1, 2, 3, 3, 4);
        stream
                .filter((n)->n>=3)
                .forEach(System.out::println);
            ;
    }



    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();
        list.add(new User(1,"a",22));
        list.add(new User(2,"d",29));
        list.add(new User(3,"c",50));
        list.add(new User(4,"e",30));
        list.add(new User(5,"f",60));

        // 流式计算
        /**
         * 作者:Vpen
         * 描述:
         * 函数式编程
         * Function     函数型接口: 给一个参数返回一个参数。
         * predicate    断定型接口: 给一个参数返回布尔值。
         * consumer     消费型接口: 给一个参数，无返回值
         * supplier     供给型接口: 不给参数，有返回值
         **/
        list.stream()
                .filter((user)-> user.getAge()>30)// 断定型接口
                .map((user)-> user.getName().toUpperCase())//函数型接口
                .sorted(String::compareTo)
                .limit(1)
                .forEach(System.out::println);// 消费型接口
    }
}

class User{
    private int id;
    private String name;
    private int age;
    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}